package com.wyvoid.forum.service.impl;

import com.wyvoid.forum.service.ITopicService;
import com.wyvoid.forum.domain.Topic;
import com.wyvoid.forum.domain.Post;
import com.wyvoid.forum.domain.Poll;
import com.wyvoid.forum.dao.ITopicDAO;
import com.wyvoid.forum.Constant;
import com.wyvoid.forum.web.search.SearchBean;
import com.wyvoid.core.persistent.hibernate.HibernatePage;
import com.wyvoid.core.persistent.Pagination;

import java.util.Map;

import org.springframework.transaction.annotation.Transactional;

/**
 * <p>51void.com</p>
 * User:cjp
 * Date: 2007-5-16
 * Time: 22:38:03
 */
public class TopicService implements ITopicService {
    private ITopicDAO topicDAO;

    public void setTopicDAO(ITopicDAO topicDAO) {
        this.topicDAO = topicDAO;
    }

    public void createTopic(Topic topic, Post firstPost, Poll poll) {
        topicDAO.create(topic);
    }

    public void editTopic(Topic topic, Post firstPost) {

    }

    public void trashTopic(long topicId) {

    }

    public HibernatePage viewTopic(long topicId, Pagination pagination) {
        return null;
    }

    public HibernatePage<Topic> getTopics(long forumId, Map orderMap, Pagination pagination) {
        return topicDAO.findTopics(forumId,orderMap,pagination);
    }

    public HibernatePage getTopics(long forumId, long categoryId, Map orderMap, int status, Pagination pagination) {
        return null;
    }

    public HibernatePage searchTopics(long forumId, String type, String keyword, int time, String way, Map orderMap, Pagination pagination) {
        return null;
    }

    public void moveTopic(long[] ids, long oldForumId, long newForumId) {

    }

    public void updateTopicIsTop(long topicId, int isTop) {

    }

    public long countTopic() {
        return topicDAO.countTopic();
    }

    public Topic getTopic(long topicId) {
        return topicDAO.getById(topicId);
    }

    public void updateTopic(Topic topic) {
        topicDAO.update(topic);
    }

    public Topic getNextTopic(long tid) {
        Topic curTopic=topicDAO.getById(tid);
        return topicDAO.getNextTopic(tid,curTopic);
    }

    public Topic getLastTopic(long tid) {
        Topic curTopic=topicDAO.getById(tid);
        return topicDAO.getLastTopic(tid,curTopic);
    }

    @Transactional
    public void deleteTopic(long tid) {
        Topic topic=topicDAO.getById(tid);
        topic.setStatus(Constant.Topic.STATUS_DEL);
    }

    @Transactional
    public void digestTopic(long tid) {
        Topic topic=topicDAO.getById(tid);
        topic.setStatus(Constant.Topic.STATUS_PRIME);
    }

    @Transactional
    public void stickTopic(long tid) {
        Topic topic=topicDAO.getById(tid);
        topic.setToped(true);
    }

    public HibernatePage<Topic> searchTopics(SearchBean searchBean, Pagination pagination) {
        return topicDAO.searchTopics(searchBean,pagination);
    }

    public HibernatePage<Topic> searchTopics2(SearchBean searchBean, Pagination pagination) {
        return topicDAO.searchTopics2(searchBean,pagination);
    }
}
